package com.hyb.algorithm.data.struct.list;

/**
 * @Author: huyanbing
 * @Date: 2021/9/22 7:23 下午
 * <p>
 * 189. 旋转数组
 * https://leetcode-cn.com/problems/rotate-array/
 */
public class RotateArray {


    public void rotate(int[] nums, int k) {
        int n = nums.length;
        int[] newArr = new int[n];

        //新开启一个数组
        // 后k个元素 +k 取余数就到前面去了
        for (int i = 0; i < n; i++) {
            newArr[(i + k) % n] = nums[i];
        }

        for(int i=0;i<n;i++){
            nums[i]=newArr[i];
        }
    }

}
